package jupiter.servlets;

import java.net.URLEncoder;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jupiter.messaging.Message;
import org.json.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MessagePushServlet extends HttpServlet {
	Logger logger = LoggerFactory.getLogger(MessagePushServlet.class);
	public void service(HttpServletRequest req, HttpServletResponse res) throws java.io.IOException {
		try{
			Message message = new Message(req);
			message.send();
			String result;
			if(message.page.equals("file.file"))
				result = "The key used is invalid.  The request will be went to development mode, shared across any request from the filesystem.";
			else
				result = "Sent to "+message.page;
			res.setContentType("text/plain");
			res.getWriter().print(result);
		    res.getWriter().flush();
		}catch(RuntimeException e){
			logger.error("RuntimeException in MessagePushServlet", e);
			throw e;
	    }catch(Exception e){
			logger.error("Exception in MessagePushServlet", e);
	    }
	}
	
}